﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SRM.DataObjects;

namespace SRM
{
    public partial class UserControls_ResumeFileUserControl : System.Web.UI.UserControl
    {
        public DataTable Applicant { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            int applicantKey = int.Parse(Session["ApplicantKey"].ToString());
            this.Applicant = SRM.DataObjects.SRM_Applicant.GetApplicant(applicantKey);
            if (!Page.IsPostBack)
            {
                if (this.Applicant.Rows.Count > 0)
                    this.Resume_FileName.Text = this.Applicant.Rows[0]["ResumeFileName"].ToString().Trim();

                if (string.IsNullOrEmpty(this.Resume_FileName.Text))
                    this.Resume_FileName.Text = "N/A";
            }
        }

        protected void Upload_Button_Click(object sender, EventArgs e)
        {
            if (Resume_RadUpload.UploadedFiles.Count > 0)
            {
                int applicantKey = int.Parse(Session["ApplicantKey"].ToString());
                this.Applicant = SRM.DataObjects.SRM_Applicant.GetApplicant(applicantKey);
                Telerik.Web.UI.UploadedFile file = Resume_RadUpload.UploadedFiles[0];
                byte[] fileBytes = new byte[file.InputStream.Length];
                file.InputStream.Read(fileBytes, 0, (int)file.InputStream.Length);
                SRM_Applicant.AddResumeFile(applicantKey, fileBytes, file.GetExtension(), file.GetName());
                this.Resume_FileName.Text = file.GetName();
            }
        }

    } // public partial class UserControls_ResumeFileUserControl : System.Web.UI.UserControl
} // namespace SRM